/******************************************************************************

    Copyright (C) 2018 ErisedMedia
    All Rights Reserved.

    This source code and any compilation or derivative thereof is the
    proprietary information of ErisedMedia and is
    confidential in nature.
    Under no circumstances is this software to be exposed to or placed under an
    Open Source License of any type without the expressed written permission of
    ErisedMedia.

******************************************************************************/

/******************************************************************************

    File:   Config.h
    Brief:  Config的头文件，配置宏开关等.

******************************************************************************/

/******************************************************************************

    Rev     Date        Author      Comments
--------------------------------------------------------------------------------
    001     20181112    RunyuanYe        Original

--------------------------------------------------------------------------------
    For consistency and standardisation retain the Section Separators.

*******************************************************************************/
#ifndef _CONFIG_H_
#define _CONFIG_H_

/******************************************************************************
*
*   INCLUDE FILES
*
******************************************************************************/


/******************************************************************************
*
*   MACROS
*
******************************************************************************/

#define debugLevelConfig    0xFF

#if defined USE_ARM
#define IS_ANROID               1
#else
#define IS_ANROID               0
#endif

#if defined USE_ANDROID
#define System(cmdStr)          RunCmd(cmdStr)
#else
#define System(cmdStr)          system(cmdStr)
#endif

#define DBG_LEVEL_ERROR1    0x00000001
#define DBG_LEVEL_ERROR2    0x00000002
#define DBG_LEVEL_ERROR3    0x00000004
#define DBG_LEVEL_ERROR4    0x00000008
#define DBG_LEVEL_WARNIN1   0x00000010
#define DBG_LEVEL_WARNIN2   0x00000020
#define DBG_LEVEL_WARNIN3   0x00000040
#define DBG_LEVEL_WARNIN4   0x00000080

#define DBG_LEVEL_1    0x00000100
#define DBG_LEVEL_2    0x00000200
#define DBG_LEVEL_3    0x00000400
#define DBG_LEVEL_4    0x00000800
#define DBG_LEVEL_5    0x00001000
#define DBG_LEVEL_6    0x00002000
#define DBG_LEVEL_7    0x00004000
#define DBG_LEVEL_8    0x00008000

#define DBG_LEVEL_9    0x00010000
#define DBG_LEVEL_10   0x00020000
#define DBG_LEVEL_11   0x00040000
#define DBG_LEVEL_12   0x00080000
#define DBG_LEVEL_13   0x00100000
#define DBG_LEVEL_14   0x00200000
#define DBG_LEVEL_15   0x00400000
#define DBG_LEVEL_16   0x00800000

#define SET_DBG_LEVEL_CONFIG(lvls) debugLevelConfig = lvls

#if ENABLE_DEBUG_PRINT

#define DBG_PRINT(...) printf("%s[%u] %s ", __FILE__, __LINE__, __FUNCTION__); printf(__VA_ARGS__)
//#define DBG_WAIT_KEY  while(true) { int c = getchar(); if('q' == c) break; }
#define DBG_WAIT_KEY this_thread::sleep_for(chrono::milliseconds(500));
//#define DBG_WAIT_KEY

#define DBG_PRINT_EX(lvl, ...) \
    do \
    { \
        if(debugLevelConfig&(lvl)) \
        { \
            printf("%s[%u] %s ", __FILE__, __LINE__, __FUNCTION__); printf(__VA_ARGS__); \
        } \
    } while(0)

#define DBG_PRINT_WK(lvl, ...) \
    do \
    { \
        if(debugLevelConfig&(lvl)) \
        { \
            printf("%s[%u] %s ", __FILE__, __LINE__, __FUNCTION__); printf(__VA_ARGS__); \
        } \
        DBG_WAIT_KEY \
    } while(0)

#else

#define DBG_PRINT(...)
#define DBG_WAIT_KEY

#define DBG_PRINT_EX(lvl, ...)

#define DBG_PRINT_WK(lvl, ...)

#endif

#define ERISED_CHECK_GOTO(Ret, GoTo) \
    do                                                  \
    {                                                   \
        if (0 != Ret)             \
        {                                           \
            printf("%s[%u] %s: err=0x%08X!\n", __FILE__, __LINE__, __FUNCTION__, Ret); \
            Ret = -1; \
            goto GoTo;           \
        }                                           \
    } while (0)

/******************************************************************************
*
*   TYPEDEFS
*
******************************************************************************/


/******************************************************************************
*
*   EXPORT DATA
*
******************************************************************************/


/******************************************************************************
*
*   EXPORT FUNCTION PROTOTYPES
*
******************************************************************************/


#endif //#ifndef _CONFIG_H_
